<?php

namespace App\Models\Virtual;

use Illuminate\Database\Eloquent\Model;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Relations;
use App\Models\Category\Category;

class Virtual extends Model
{
    use HasDateTimeFormatter;

    protected $table = 'virtuals';
    protected $fillable = [
        'id', 'unit_id', 'category_id', 'unit_name', 'page_number',
        'title', 'image', 'video', 'is_read', 'mobile_image', 'unit_main_name'
    ];

    const IS_READ_ON = 1;
    const IS_READ_OFF = 0;

    public static array $isShowMap = [
        self::IS_READ_ON => '跟读模式',
        self::IS_READ_OFF => '阅读模式',
    ];

    public function category(): Relations\BelongsTo
    {
        return $this->belongsTo(Category::class);
    }

    public function virtual_word(): Relations\HasMany
    {
        return $this->hasMany(VirtualWord::class);
    }
}
